use std::collections::HashSet;
use chrono::{DateTime, Local};
use serde::{Serialize, Deserialize};
use crate::business::websocket::dto::json_serialize::date_time_serde;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ExceptionResp {
    #[serde(rename = "errorStatus")]
    pub error_status: i32,

    #[serde(rename = "errorMsg")]
    pub error_msg: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OkReq {

    pub coder: i16,

    #[serde(rename = "otherInfo")]
    pub other_info: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OkResp {
    #[serde(rename = "successDataTime", with = "date_time_serde")]
    pub success_data_time: DateTime<Local>,

    #[serde(rename = "localSeq")]
    pub local_seq: Option<String>,
    pub coder: i16,
    #[serde(rename = "otherInfo")]
    pub other_info: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OkListResp {

    #[serde(rename = "localSeqSet")]
    pub local_seq_set: HashSet<String>,

    #[serde(rename = "successDataTime", with = "date_time_serde")]
    pub success_data_time: DateTime<Local>,

    #[serde(rename = "localSeq")]
    pub local_seq: Option<String>,
    pub coder: i16,
    #[serde(rename = "otherInfo")]
    pub other_info: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LoginCookie {
    pub token: String,
    pub auth_token: String,
    pub use_id: String,
    pub machine_code: String,
    pub expired: u64,
}

impl LoginCookie {
    pub fn is_expired(&self) -> bool {
        let now = Local::now().timestamp_millis() as u64;
        log::info!("now: {}, expired: {}", now, self.expired);
        now > self.expired
    }
}

impl ExceptionResp {
    pub fn new(error_msg: String) -> ExceptionResp {
        ExceptionResp {
            error_status: -9999,
            error_msg,
        }
    }
}